using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using School.Entities;
using System.Reflection;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(option => {
  var xmlPath = Path.Combine(AppContext.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml");
  option.IncludeXmlComments(xmlPath, true);
  option.SwaggerDoc("v1", new OpenApiInfo
  {
    Title = $"{Assembly.GetExecutingAssembly().GetName().Name}接口文档",
    Version = "v1.0"
  });
});


//SQL Server
builder.Services.AddDbContext<SchoolContext>(opt => opt.UseSqlServer(builder.Configuration.GetConnectionString("Default") ?? throw new("数据库连接失败")));

var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.MapControllers();
app.Run();
